﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PurchaseManagementSystem.DBModel;
using System.Data.SqlClient;

namespace PurchaseManagementSystem
{
    /// <summary>
    /// 竞标功能__王佳
    /// </summary>
    public partial class bid : Form
    {
        public bid()
        {
            InitializeComponent();
        }

        private int proID = 0;
        /// <summary>
        /// 商品编号
        /// </summary>
        public int ProID
        {
            get { return proID; }
            set { proID = int. Parse(tb_ID.Text) ; }
        }

        private string proName;
        /// <summary>
        /// 商品名称
        /// </summary>
        public string ProName
        {
            get { return proName; }
            set { proName = tb_Name .Text .ToString (); }
        }

        private int proPrice = 0;
        /// <summary>
        /// 商品价格
        /// </summary>
        public int ProPrice
        {
            get { return proPrice; }
            set { proPrice = int.Parse (tb_Price.Text); }
        }

        private int proBal = 0;
        /// <summary>
        /// 商品库存量
        /// </summary>
        public int ProBal
        {
            get { return proBal; }
            set { proBal = int.Parse (tb_Ballace .Text ); }
        }

        private string supplier;

        public string Supplier
        {
            get { return supplier; }
            set { supplier = tb_Supplier .Text .ToString (); }
        }


        private void tb_ID_TextChanged(object sender, EventArgs e)
        {

        }

        private void btn_bid_Click(object sender, EventArgs e)
        {
            try
            {
                if (tb_ID.Text == "")
                {
                    MessageBox.Show("请输入商品编号！");
                }
                else if (tb_Name.Text == "")
                {
                    MessageBox.Show("请输入商品名称！");
                }
                else if (tb_Supplier.Text == "")
                {
                    MessageBox.Show("请输入供应商编号！");
                }
                else if (tb_Price.Text == "")
                {
                    MessageBox.Show("请输入供应商编号！");
                }
                else if (tb_Ballace.Text == "")
                {
                    MessageBox.Show("请输入商品库存！");
                }
                else
                {
                    ProID = int.Parse(tb_ID.Text);
                    ProBal = int.Parse(tb_Ballace.Text);
                    ProName = tb_Name.Text.ToString();
                    Supplier = tb_Supplier.Text.ToString();
                    ProPrice = int.Parse(tb_Price.Text);


                    MessageBox.Show("  商品编号" + "              " + ProID.ToString() + Environment.NewLine
                                  + "  商品名称" + "              " + ProBal.ToString() + Environment.NewLine
                                  + "  商品价格" + "              " + ProName + Environment.NewLine
                                  + "  商品库存" + "              " + Supplier + Environment.NewLine
                                  + "  供应商  " + "               " + ProPrice.ToString());

                    DBServer.SearchOrderID(ProID, ProBal, ProName, Supplier, ProPrice);

                    MessageBox.Show("执行成功！\n 请继续添加或退出程序");
                    Reset();
                }
            }

            catch (Exception ex)
            {
                MessageBox .Show( ex.Message.ToString() + "添加失败！\n请输入正确的数据");
            }
        }

        private void Reset()
        {
            btn_bid.Text = "继续竞标";
            tb_ID .Text = null;
            tb_Name.Text = null;
            tb_Price.Text = null;
            tb_Supplier.Text = null;
            tb_Ballace.Text = null;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void bid_Load(object sender, EventArgs e)
        {

        }

    }
}
